package com.reader.api.constants;

/**
 * @author liujianqing
 * @date 2018/10/29
 */
public enum GoodsTypeEnum {
    MAGAZUNE("杂志", "magazine"),
    COURSE("课程", "course");

    private String name;
    private String code;

    private GoodsTypeEnum(String name, String code) {
        this.name = name;
        this.code = code;
    }

    /**
     * 获取名称.
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * 获取编码.
     * @return
     */
    public String getCode() {
        return code;
    }

    /**
     * 根据编码获取枚举类型.
     * @param code
     * @return
     */
    public static GoodsTypeEnum getEnumByCode(String code) {
        for (GoodsTypeEnum e : GoodsTypeEnum.values()) {
            if (e.getCode() == code) {
                return e;
            }
        }
        return null;
    }

    /**
     * 根据编码获取名称.
     * @param code
     * @return
     */
    public static String getNameByCode(String code) {
        for (PayPlatformTypeEnum e : PayPlatformTypeEnum.values()) {
            if (e.getCode() == code) {
                return e.getName();
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name;
    }
}
